


public class TreeNode implements Comparable {
	TreeNode parent,left,right;
	TreeNode qnext,qprev;
	int column, level;
	int freq;
	int code;
	int afterCode;
	int bitCode[];
	boolean booleanBitCode[];
	int afterCodeLen;
	boolean isLeaf;
	TreeNode(TreeNode theParent, int frequency, int thecode) {
		parent = theParent;
		freq = frequency;
		code = thecode;
		isLeaf = false;
	}
	TreeNode () {
		isLeaf = false;
		left = right = null;
	}
	public int compareTo(Object obj) {
		TreeNode tm = (TreeNode) obj;
		if(bitCode != null) {
			if(code < tm.code) return -1;
			if(code == tm.code) return 0;
			if(code > tm.code) return 1;
		}
		else {
			if(freq < tm.freq) return -1;
			if(freq == tm.freq) return 0;
			if(freq > tm.freq) return 1;
		}
		return 0;
	}
	boolean isRoot() {
		if (parent == null) return true;
		return false;
	}
	boolean isLeaf() {
		if((left == null) && (right == null)) return true;
		return false;
	}
    public void updateArray(String printArray[][]) {
    	if(isLeaf) printArray[level*2][column*2] = Integer.toString(afterCode);
    	else printArray[level*2][column*2] = "I";
    	if(left != null) {
    		int colDif = column - left.column;
    		left.updateArray(printArray);
    		if(colDif > 0) {
    			printArray[(level*2)+1][(column * 2)] = "^";
    			for(int i=1; i < (colDif * 2); i++) {
    				printArray[(level*2)+1][(column * 2) - i] = "-";
    			}
    		}
    		printArray[(level*2)+1][(column*2)-(colDif*2)] = "/";
    	}
    	if(right != null) {
    		right.updateArray(printArray);
    		int colDif = right.column - column;
    		if(colDif > 0) {
    			printArray[(level*2)+1][(column * 2)] = "^";
    			for(int i=1; i < (colDif * 2); i++) {
    				printArray[(level*2)+1][(column * 2) + i] = "-";
    			}
    		}
    		printArray[(level*2)+1][(column*2)+((colDif*2))] = "\\";
    			
    	}
    }
	 
}
